{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Context Menu Action"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from beakerx import *\n",
    "from beakerx.object import beakerx\n",
    "\n",
    "mapList = [\n",
    "   {\"a\":1, \"b\":2, \"c\":3},\n",
    "   {\"a\":4, \"b\":5, \"c\":6},\n",
    "   {\"a\":7, \"b\":8, \"c\":5}\n",
    "]\n",
    "display1 = TableDisplay(mapList)\n",
    "\n",
    "def plusOne(row, column, tabledisplay):\n",
    "    tabledisplay.values[row][column] = int(tabledisplay.values[row][column]) + 1\n",
    "\n",
    "display1.addContextMenuItem(\"plusOne\", plusOne)\n",
    "display1.addContextMenuItem(\"tag1ByStr\", \"tag1\");\n",
    "\n",
    "display1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by string parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag1"
    ]
   },
   "outputs": [],
   "source": [
    "details = display1.details\n",
    "print(str(details.row) + ':' + str(details.col) + '=' + str(display1.values[details.row][details.col]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell1 expected result\n",
    "Image(\"../../resources/img/python/tableActions/cell1_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell1 expected result after menu action\n",
    "Image(\"../../resources/img/python/tableActions/cell1_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by closure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display1a = TableDisplay(mapList)\n",
    "\n",
    "def runTagFunc(row, column, tabledisplay):\n",
    "    beakerx.runByTag(\"tag1a\")\n",
    "\n",
    "display1a.addContextMenuItem(\"runTagFunc\", runTagFunc)\n",
    "display1a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag1a"
    ]
   },
   "outputs": [],
   "source": [
    "details = display1a.details\n",
    "print(str(details.row) + ':' + str(details.col) + '=' + str(display1a.values[details.row][details.col]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DoubleClick Action"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display2 = TableDisplay(mapList)\n",
    "\n",
    "def dclick(row, column, tabledisplay):\n",
    "    tabledisplay.values[row][column] =  int(tabledisplay.values[row][column]) + 1\n",
    "\n",
    "display2.setDoubleClickAction(dclick)\n",
    "display2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell2 expected result\n",
    "Image(\"../../resources/img/python/tableActions/cell2_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell2 expected result after doubleAction click\n",
    "Image(\"../../resources/img/python/tableActions/cell2_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by string parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display3 = TableDisplay(mapList)\n",
    "display3.setDoubleClickAction(\"tag3\")\n",
    "display3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag3"
    ]
   },
   "outputs": [],
   "source": [
    "details = display3.details\n",
    "print(str(details.row) + ':' + str(details.col) + '=' + str(display3.values[details.row][details.col]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell3 expected result\n",
    "Image(\"../../resources/img/python/tableActions/cell3_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by closure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from beakerx.object import beakerx\n",
    "\n",
    "def dclick(row, column, tabledisplay):\n",
    "    beakerx.runByTag(\"tag4\")\n",
    "\n",
    "display4 = TableDisplay(mapList)\n",
    "display4.setDoubleClickAction(dclick)\n",
    "display4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag4"
    ]
   },
   "outputs": [],
   "source": [
    "details = display4.details\n",
    "print(str(details.row) + ':' + str(details.col) + '=' + str(display4.values[details.row][details.col]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%groovy\n",
    "// cell4 expected result\n",
    "Image(\"../../resources/img/python/tableActions/cell4_case1.png\")"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {
    "height": "32px",
    "width": "307px"
   },
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": false,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
